package com.example.demo.controller;

import com.example.demo.entity.User;
import com.example.demo.vo.PageableResult;
import com.example.demo.vo.Result;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author shenb
 * @date 2022-06-28 9:51
 */
@RestController
@RequestMapping("users")
public class UserController {

    @GetMapping
    public PageableResult<User> getUsersPage(
            @RequestParam(value = "page", required = false, defaultValue = "1") Integer page,
            @RequestParam(value = "page_size", required = false, defaultValue = "10") Integer pageSize
    ) {
        return new PageableResult<>();
    }

    @GetMapping("error")
    public Result<User> error() {
        throw new IllegalArgumentException("User error");
    }


    @PostMapping
    public User user(@RequestBody User user) {
        return user;
    }
}
